// GradeRepository.java
package com.example.studentmanagement2.repository.Repository;

import com.example.studentmanagement2.model.Grade;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;

public interface GradeRepository1 extends JpaRepository<Grade, Long> {

    @Query("SELECT g.courseId, AVG(g.score) " +
            "FROM Grade g " +
            "JOIN Student s ON g.studentId = s.id " +  // 关联 Student 表
            "WHERE s.className = :className " +        // 使用 Student 的 className
            "GROUP BY g.courseId")
    List<Object[]> findAverageScoresByClass(@Param("className") String className);
}